package com.neusoft.neumooc.dao;

import java.util.List;

import org.springframework.stereotype.Repository;

import com.neusoft.core.common.BaseDAO;
import com.neusoft.core.common.exception.DAOException;
import com.neusoft.neumooc.vo.ParamVO;

@Repository
public class ParamDAOImpl extends BaseDAO implements ParamDAO {

    private static final String SQL_GET_ALL_PARAMS = 
        "SELECT paramId as paramId, " +
               "paramName as paramName, " +
               "paramValue as paramValue " +
        "FROM cw_params";
        
    private static final String SQL_UPDATE_PARAM = 
        "UPDATE cw_params SET paramValue = :paramValue WHERE paramId = :paramId";

    @Override
    public List<ParamVO> getAllParams() throws DAOException {
        try {
            List<ParamVO> params = this.queryForBeanList(SQL_GET_ALL_PARAMS, ParamVO.class);
            log.debug("查询到的参数列表: " + params);
            return params;
        } catch (Exception e) {
            log.error("查询参数列表失败", e);
            throw new DAOException("查询参数列表失败", e);
        }
    }

    @Override
    public boolean updateParams(List<ParamVO> params) throws DAOException {
        try {
            for(ParamVO param : params) {
                this.update(SQL_UPDATE_PARAM, param);
            }
            return true;
        } catch(Exception e) {
            log.error("更新参数失败", e);
            return false;
        }
    }
} 